﻿using System;
using System.IO;
using IMDBServiceAPI;

namespace IMDBServiceConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            MovieInfo movie = null;
            string strMovieTitle = string.Empty;
            foreach (string strFileName in Directory.GetFiles(@"H:\Movies"))
            {
                strMovieTitle =
                    Path.GetFileNameWithoutExtension(
                        strFileName);
                Console.WriteLine(
                   strMovieTitle);
                try
                {
                    movie = MovieInfo.GetMovieInfo(strMovieTitle);                    
                    Console.WriteLine(movie);
                }
                catch (RetrievalFailureException exc) { Console.WriteLine(exc.Message); }
                finally { Console.WriteLine(); }
            }

                      
            //MovieInfo.RetrieveIMDBMovieUrl("Ice Age 3 Dawn Of The Dinosaurs");

            //HttpWebRequest request =
            //    (HttpWebRequest)WebRequest.Create("http://www.imdb.com/title/tt0367882/");
            //HttpWebResponse response =
            //    (HttpWebResponse)request.GetResponse();
            //using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            //{
            //    File.WriteAllText(
            //        Path.Combine(
            //            Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
            //            "MyFile2.txt"), reader.ReadToEnd());
            //}



            //string content = File.ReadAllText(
            //    Path.Combine(
            //        Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
            //        "MyFile.txt"));

            //string urlExpression =
            //    @"<b>Titles \(Partial Matches\)(.*)/title/(?<title>.*)/(.*)onclick(.*)</a>";
            //Console.WriteLine(Regex.Match(content, urlExpression,RegexOptions.RightToLeft).Groups["title"].Value);


            //string[] expressions = 
            //{
               
            //    //@"<b>Popular Titles(.*)/title/(?<title>.*)/(.*)onclick(.*)</a>",
            //    //@"<b>Titles \(Exact Matches\)(.*)/title/(?<title>.*)/(.*)onclick(.*)</a>",
            //    //@"<b>Titles \(Partial Matches\)(.*)/title/(?<title>.*)/(.*)onclick(.*)</a>",
            //    //@"<title>(?<title>.*)\((?<year>\d*)\)</title>",
            //    //@"<div class=""starbar-meta"">\s*<b>(?<rating>[\d\.]*)/(.*)</b>",
            //    //@"<h5>Genre:</h5>\s*<div class=""info-content"">\s*(?<area>.*)\s*</div>"
            //};

            //string fileContent = File.ReadAllText(
            //    Path.Combine(
            //        Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
            //        "After Life.txt"));

            //Regex expression = default(Regex);
            //string strArea = string.Empty;
            //foreach (string strExpr in expressions)
            //{
            //    Console.WriteLine(strExpr);
            //    //Console.WriteLine(
            //    //    Regex.Match(fileContent, strExpr)
            //    //        .Groups["title"].Value);
            //    //Console.WriteLine(
            //    //    Regex.Match(fileContent, strExpr, RegexOptions.Multiline)
            //    //        .Groups["year"].Value);
            //    //Console.WriteLine(
            //    //    Regex.Match(fileContent, strExpr)
            //    //        .Groups["rating"].Value);
            //    //strArea = Regex.Match(fileContent, strExpr)
            //    //        .Groups["area"].Value;
            //    //Console.WriteLine(strArea);
            //    //Console.WriteLine(
            //    //    Regex.Match(fileContent, strExpr, RegexOptions.Multiline).Value);
            //    Console.WriteLine(
            //        Regex.Match(
            //        Regex.Match(fileContent, strExpr)
            //            .Groups["area"].Value,
            //        @"<a href=""/title/(?<url>([\w\d]*))/").Groups["url"].Value);
            //    //foreach (Match match in Regex.Matches(strArea, @"<a href=""/title/(?<url>([\w\d]*))/"))
            //    //{
            //    //    Console.WriteLine(match.Value);
            //    //    Console.WriteLine(match.Groups["url"].Value);
            //    //}
            //}

            //foreach (Match match in Regex.Matches(strArea, @"<a href=""/Sections/Genres/(?<genre>\w*)/"))
            //{
            //    Console.WriteLine(match.Value);
            //    Console.WriteLine(match.Groups["genre"].Value);
            //}
        }
    }
}
